// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import './assets/reset.css'
import g from './common/g.js'
import store from './store'
import 'mint-ui/lib/style.css'
import config from './common/config'

Vue.config.productionTip = false
Vue.prototype.$g = g

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store: store,
  router,
  components: { App },
  template: '<App/>',
  mounted () {
    let ua = navigator.userAgent.toLowerCase()
    if (ua.indexOf('micromessenger') > -1) {
      this.weixinLogin()
    } else {
      this.$router.push('/error/请在微信浏览器中打开')
    }
  },
  methods: {
    /* 微信登录 */
    weixinLogin () {
      // this.$store.dispatch('getAuth')
      store.dispatch('getAuth')
      let path = window.location.href.split('#')
      if (store.state.auth.status !== 'in') {
        localStorage.setItem('url', (path[1] || '/'))
        console.log(path[1])
        window.location.href = config.apiURI + 'interfaces/createstate/kkschool'
      }
    }
  }
})
